#ifndef __LIB_GUI_SURFACE_H
#define __LIB_GUI_SURFACE_H

#include<types.h>

typedef struct
{
    int x, y;
    uint32_t w, h;
}gui_rect_t;

typedef struct
{
    uint32_t w, h;
    uint32_t* pixel;
}gui_surface_t;


#define gui_surface_getpixel_fast(surface,x,y)  \
 (surface)->pixel[(y) * (surface)->w + (x)]
#define gui_surface_putpixel_fast(surface,x,y,color) \
 (surface)->pixel[(y)*(surface)->w+(x)]=(color)

static inline void gui_rect_init(gui_rect_t* rect, int x, int y, uint32_t w, uint32_t h)
{
    rect->x = x;
    rect->y = y;
    rect->w = w;
    rect->h = h;
}

static inline int gui_rect_valid(gui_rect_t* rect)
{
    if (rect->w <= 0 || rect->h <= 0)
        return 0;
    return 1;
}

static inline void gui_rect_merge(gui_rect_t* dst, gui_rect_t* src)
{
    dst->x = min(dst->x, src->x);
    dst->y = min(dst->h, src->h);
    dst->h = max(dst->h, src->h);
    dst->w = max(dst->w, src->w);
}

static inline void gui_surface_init(gui_surface_t* surface, uint32_t width, uint32_t height, uint32_t* pixel)
{
    surface->w = width;
    surface->h = height;
    surface->pixel = pixel;
}

gui_surface_t* gui_surface_create(uint32_t width, uint32_t height);
int gui_surface_destroy(gui_surface_t* surface);
int gui_surface_resize(gui_surface_t* surface, uint32_t width, uint32_t height);
void gui_surface_clear(gui_surface_t* surface);
int gui_surface_putpixel(gui_surface_t* surface, int x, int y, uint32_t color);
int gui_surface_getpixel(gui_surface_t* surface, int x, int y, uint32_t* color);
void gui_surface_vline(gui_surface_t* surface, int x, int y1, int y2, uint32_t color);
void gui_surface_hline(gui_surface_t* surface, int x1, int x2, int y, uint32_t color);
int gui_surface_line(gui_surface_t* surface, int x1, int y1, int x2, int y2, uint32_t color);
void gui_surface_rect_ex(gui_surface_t* surface, int x1, int x2, int y1, int y2, uint32_t color);
void gui_surface_rectfill_ex(gui_surface_t* surface, int x1, int y1, int x2, int y2, uint32_t color);
void gui_surface_rect(gui_surface_t* surface, int x, int y, uint32_t width, uint32_t height, uint32_t color);
void gui_surface_rectfill(gui_surface_t* surface, int x, int y, uint32_t width, uint32_t height, uint32_t color);
void gui_surface_blit(gui_surface_t* src, gui_rect_t* srcrect, gui_surface_t* dst, gui_rect_t* dstrect);
void gui_surface_blit_scaled_lower(gui_surface_t* src, gui_rect_t* srcrect, gui_surface_t* dst, gui_rect_t* dstrect);
void gui_surface_blit_scaled(gui_surface_t* src, gui_rect_t* srcrect, gui_surface_t* dst, gui_rect_t* dstrect);












#endif 

